home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / Apps / SoundApps / SNDed / Source / SoundEditor.m < prev    next >
Encoding:
Text File  |  1995-06-12  |  5.6 KB  |  259 lines

  1.  
  2. /* Generated by Interface Builder */
  3.  
  4. extern void energy();
  5.  
  6.  
  7. #import "SoundEditor.h"
  8.  
  9. #import <appkit/View.h>
  10. #import <appkit/appkit.h>
  11. #import <soundkit/soundkit.h>
  12. #import <strings.h>
  13.  
  14. @implementation SoundEditor
  15.  
  16. static newLocation(NXPoint *p)
  17. {
  18.     // compute the location of the new window
  19.     // shifted to the botom-right
  20.     static count = 0;
  21.     p->x += (20.0 * count);
  22.     p->y -= (25.0 * count);
  23.     count = (count > 10)? 0 : count+1;
  24. }
  25.  
  26.  
  27. +new
  28. {
  29.   // create the new window
  30.   // and initialize the different parameters
  31.   self = [super new];
  32.   [NXApp loadNibSection:"SoundEditor.nib" owner:self];
  33.  
  34.   // browser purpose
  35.   strcpy(SignalFileName,"SoundEditor.snd");
  36.   strcpy(SignalDirName,".");
  37.   strcpy(EnergyFileName,"E.SoundEditor.snd");
  38.   strcpy(EnergyDirName,"./");
  39.  
  40.   // view attributes
  41.   [SoundSignal setAutodisplay:YES];
  42.   [SoundSignal setAutoscale:  YES];
  43.   [SoundZoom   setAutodisplay:YES];
  44.   [SoundZoom   setAutoscale:  YES];
  45.   [SoundEnergy setAutodisplay:YES];
  46.   [SoundEnergy setAutoscale:  YES];
  47.   [SoundEnergy setEnabled:    NO ];
  48.   [SoundEnergy setDisplayMode:SK_DISPLAY_WAVE];
  49.  
  50.   // view defaults contents
  51.   sndSignal = [Sound new];
  52.   [SoundSignal setSound:sndSignal];
  53.   sndZoom = [Sound new];
  54.   [SoundZoom setSound:sndZoom];
  55.   sndEnergy = [Sound new];
  56.   [SoundEnergy setSound:sndEnergy];
  57.  
  58.   return self;
  59. }
  60.  
  61.  
  62. - setSoundZoom:anObject
  63. {
  64.     SoundZoom = anObject;
  65.     return self;
  66. }
  67.  
  68. - setSoundEnergy:anObject
  69. {
  70.     SoundEnergy = anObject;
  71.     return self;
  72. }
  73.  
  74. - setSoundWindow:anObject
  75. {
  76.     NXRect theFrame;
  77.     SoundWindow = anObject;
  78.     [SoundWindow getFrame:&theFrame];
  79.     newLocation(&theFrame.origin);
  80.     [SoundWindow moveTo:theFrame.origin.x :theFrame.origin.y];
  81.     return self;
  82. }
  83.  
  84. - setSoundSignal:anObject
  85. {
  86.     SoundSignal = anObject;
  87.     return self;
  88. }
  89.  
  90. - PlayAllZoom:sender
  91. {
  92.     // play the whole zoom sound
  93.     id ZoomSound;
  94.     ZoomSound = [Sound new];
  95.     ZoomSound = [SoundZoom sound];
  96.     [ZoomSound play];
  97.     return self;
  98. }
  99.  
  100. - Play:sender
  101. {
  102.     // play the current selection of the signal sound
  103.     [SoundSignal play:sender];
  104.     return self;
  105. }
  106.  
  107. - ZoomOut:sender
  108. {
  109.     // zoom out from zoom sound to signal sound
  110.         [SoundZoom selectAll:sender];
  111.         [SoundZoom      copy:sender];
  112.         [SoundSignal   paste:sender];
  113.     [self ComputeEnergy];
  114.     return self;
  115. }
  116.  
  117. - PlayZoom:sender
  118. {
  119.     // play the current selection of the zoom sound
  120.     [SoundZoom play:sender];
  121.     return self;
  122. }
  123.  
  124. - Record:sender
  125. {
  126.     // record from the microphone to the selected part of the signal sound
  127.     static int state=0;
  128.     state = (++state)%2;
  129.     if (state) {
  130.       [SoundSignal record:sender];
  131.       }
  132.     else {
  133.       [SoundSignal stop:sender];
  134.       [self ComputeEnergy];
  135.       }
  136.     return self;
  137. }
  138.  
  139. - PlayAll:sender
  140. {
  141.     // play the whole signal sound
  142.     id SignalSound;
  143.     SignalSound = [Sound new];
  144.     SignalSound = [SoundSignal sound];
  145.     [self ComputeEnergy];
  146.     [SignalSound play];
  147.     return self;
  148. }
  149.  
  150. - Load:sender
  151. {
  152.     id   theBrowser;
  153.     id   aSound;
  154.     int  result;
  155.     char *slashPtr;
  156.  
  157.     // open a browser and load the selected file
  158.     theBrowser = [OpenPanel new];
  159.     [theBrowser setRequiredFileType: "snd"];
  160.     [theBrowser setDirectory: SignalDirName];
  161.  
  162.     result = [theBrowser runModal];
  163.     if (result) {
  164.       aSound = [Sound new];
  165.       strcpy(SignalFileName,[theBrowser filename]);
  166.       strcpy(SignalDirName,SignalFileName);
  167.       slashPtr = rindex (SignalDirName, '/');
  168.       if (slashPtr) {
  169.         *slashPtr = '\0';
  170.         }
  171.       [aSound readSoundfile:SignalFileName];
  172.       [SoundSignal setSound:aSound];
  173.       strcpy(EnergyFileName,"E.");
  174.       strcat(EnergyFileName,strrchr(SignalFileName,'/')+1);
  175.       [SoundWindow setTitle:strrchr(SignalFileName,'/')+1];
  176.       [self ComputeEnergy];
  177.       }
  178.     return self;
  179. }
  180.  
  181. - ZoomIn:sender
  182. {
  183.     // zoom in from the signal sound to the zoom sound
  184.     int firstSample, sampleCount;
  185.     id aSound;
  186.     aSound = [Sound new];
  187.     [SoundSignal getSelection:&firstSample size:&sampleCount];
  188.     [aSound copySound:[SoundSignal sound]];
  189.     if (firstSample) {
  190.       [aSound deleteSamplesAt:0 count:firstSample-1];
  191.       }
  192.     if (sampleCount) {
  193.       [aSound deleteSamplesAt:sampleCount count:[aSound sampleCount]];
  194.       }
  195.     [SoundZoom setSound:aSound];
  196.     return self;
  197. }
  198.  
  199. - Show:sender
  200. {
  201.     [SoundWindow makeKeyAndOrderFront:self];
  202.     return self;
  203. }
  204.  
  205. - Save:sender
  206. {
  207.     id  theBrowser;
  208.     id  aSound;
  209.     int result;
  210.  
  211.     // open a browser and save the selected file
  212.     theBrowser = [SavePanel new];
  213.     [theBrowser setRequiredFileType: "snd"];
  214.     result = [theBrowser runModalForDirectory: SignalDirName
  215.                     file: SignalFileName];
  216.     if (result) {
  217.       aSound = [Sound new];
  218.       aSound = [SoundSignal sound];
  219.       sndSignal = [SoundSignal sound];
  220.       strcpy(SignalFileName,[theBrowser filename]);
  221.       [aSound writeSoundfile:SignalFileName];
  222.       [SoundWindow setTitle:strrchr(SignalFileName,'/')+1];
  223.       }
  224.     return self;
  225. }
  226.  
  227. - ComputeEnergy
  228. {
  229.     // compute the energy of the signal sound
  230.     // and store it in the energy view
  231.     char newEnergy[100];
  232.     char SystemCommand[200];
  233.     id aSound;
  234.     aSound = [Sound new];
  235.  
  236.     if ([[SoundSignal sound] sampleCount]) {
  237.       [[SoundSignal sound] writeSoundfile: EnergyFileName];
  238.       energy (EnergyFileName);
  239.       strcpy(newEnergy, EnergyFileName);
  240.       strcat(newEnergy, ".energy");
  241.       [aSound readSoundfile:newEnergy];
  242.       [SoundEnergy setSound: aSound];
  243.  
  244.       // cleanup purpose
  245.       strcpy(SystemCommand, "rm ");
  246.       strcat(SystemCommand, EnergyFileName);
  247.       system ( SystemCommand );
  248.       strcpy(SystemCommand, "rm ");
  249.       strcat(SystemCommand, newEnergy);
  250.       system ( SystemCommand );
  251.       }
  252.  
  253.     return self;
  254.  
  255. }
  256.  
  257.  
  258. @end
  259.